home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: rice@tiac.net (Ken Rice)
- Newsgroups: comp.std.c++
- Subject: Is this legal?
- Date: 26 Feb 1996 18:07:38 PST
- Organization: The Internet Access Company
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <rice-2602962041230001@luna.tiac.net>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: Mon, 26 Feb 1996 20:41:23 -0500
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMTJnf0y4NqrwXLNJAQHm+QH/cN4MXS9DQi1DnRUMLlP8gOyf9/ldboH8
- tHBhdIrA3guLac4gl8+Z3sVZXzaFrTTauS3R3yEc/DYpULWmF09rjQ==
- =eOjO
- Originator: austern@isolde.mti.sgi.com
-
- template < class ItemType > class T
- {
- public:
- T(){}
- virtual ~T(){}
- ItemType mArr;
- };
-
- void main(void)
- {
- T<int>* pA = nil;
- dynamic_cast < T<int>* > (pA);
- }
-
- Our compiler reports this error:
- Error : illegal use of incomplete struct/union/class
- x.cp line 12 dynamic_cast < T<int>* > (pA);
-
- Note that T<int> is not used in a way that causes it to be instantiated until
- it gets to the dynamic_cast. The april 95 draft sec 5.2.6 [expr.dynamic.cast]
- says "Types shall not be defined in a dynamic_cast."
-
- So, the question is, does using a template that has not been instantiated
- before count as 'defining a type' (as the compiler seems to think), or is
- the code legal?
-
- The example can be made to compile by gratuitously declaring a variable of
- type T<int> before the dynamic_cast line to force implicit instantiation,
- but that seems a bit kludgy.
-
- Thanks,
- Ken Rice.
-
- --
- Ken Rice
- rice@tiac.net
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-